import numpy as np
import csv

def load_data(file_path):
    data=[]
    with open(file_path, 'r', encoding='utf-8')as file:
        reader =csv.reader(file)
        header=next(reader)
        math_index = header.index('math_score')
        english_index = header.index('english_score')
        python_index = header.index('python_score')
        for row in reader:
            data.append([float(row[math_index]),float(row[english_index]),float(row[python_index])])
        return np.array(data)


def calculate_statistics(data):
    means=np.round(np.mean(data,axis=0),1)
    medians=np.round(np.median(data,axis=0),1)
    variances=np.round(np.var(data,axis=0),1)
    stds=np.round(np.std(data,axis=0),1)
    result_dict={
        "means":means,"medians": medians,"variances":variances,"stds":stds
    }
    return result_dict


def print_results(stats):
    subjects=['Math','English','Python']
    for i ,subject in enumerate(subjects):
        print(f"{subject}:")
        print(f"    Average:{stats['means'][i]}")
        print(f"    Median:{stats['medians'][i]}")
        print(f"    Variance::{stats['variances'][i]}")
        print(f"    Standard Deviation:{stats['stds'][i]}")
        best_subject_index=np.argmax(stats['means'])
        most_consistent_subject_index=np.argmax(stats['stds'])
    print(f"Best Subject:{subjects[best_subject_index]}")
    print(f"Most Consistent Subject(Lowest Std):{subjects[most_consistent_subject_index]}({stats['stds'][most_consistent_subject_index]})")

def main():
    data = load_data('scores.csv')
    
    stats = calculate_statistics(data)

    print_results(stats)

if __name__ == "__main__":
    main()
